package com.sample.springbatch.job.sample.config;

import com.sample.springbatch.job.config.BaseConfig;
import com.sample.springbatch.job.sample.processor.FieldJavaTypeProcessor;
import com.sample.springbatch.job.sample.reader.FieldJavaTypeFlatFileItemReader;
import com.sample.springbatch.model.FieldJavaType;
import com.sample.springbatch.model.RepayOrderInfo;
import org.springframework.batch.core.Job;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.launch.support.RunIdIncrementer;
import org.springframework.batch.item.file.FlatFileParseException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 字段类型转换实例
 *
 * @author zwg
 * @date 2019-03-20 14:31
 **/
@Configuration
public class FieldJavaTypeConfig extends BaseConfig {


    @Autowired
    private FieldJavaTypeFlatFileItemReader fieldJavaTypeFlatFileItemReader;
    @Autowired
    private FieldJavaTypeProcessor fieldJavaTypeProcessor;

    @Bean(name = "fieldJavaTypeJob")
    public Job fieldJavaTypeJob() {
        return jobBuilderFactory.get("fieldJavaTypeJob")
                .incrementer(new RunIdIncrementer())
                .listener(myJobListener) //增加对job的监听
                .flow(fieldJavaTypeJobStep())
                .end()
                .build();
    }

    @Bean(name = "fieldJavaTypeJobStep")
    public Step fieldJavaTypeJobStep() {
        return stepBuilderFactory.get("fieldJavaTypeJobStep")
                .<FieldJavaType, FieldJavaType> chunk(1)
                .reader(fieldJavaTypeFlatFileItemReader)
                .processor(fieldJavaTypeProcessor)
                .build();
    }
}

